//**************************************************************************
//
//         (C) Okulov Rostislav, 2011
//
/*
 ***************************************************************************
 *                                                                         *
 *   This source is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This code is distributed in the hope that it will be useful, but      *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 *                                                                         *
 */

import java.util.*;
import java.io.Serializable;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;


class TVector {
    public float x,y,z;

    public TVector(float value) {
        this(value, value, value);
    }

    public TVector(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    public TVector add(TVector v1, TVector v2) {
        float x = v1.x + v2.x;
        float y = v1.y + v2.y;
        float z = v1.z + v2.z;
        return new TVector(x, y, z);
    }
    
    public TVector le_MultVector(TVector Vector, float Num) {
        float x = Vector.x * Num;
        float y = Vector.y * Num;
        float z = Vector.z * Num;
        return new TVector (x, y, z);
    }
    
    public double le_DistancePoints(TVector Point1, TVector Point2) {

        return (Math.sqrt((Point2.x - Point1.x) * (Point2.x - Point1.x) +
                (Point2.y - Point1.y) * (Point2.y - Point1.y) +
                (Point2.z - Point1.z) * (Point2.z - Point1.z)));
        
    }
    
	public TVector le_Sphere2SphereCollisionWithRespond(TVector center2,
                                                        TVector center1,
                                                        float radius1,
                                                        float radius2) {
        double distance;
        double D;
        distance = le_DistancePoints(center2, center1);
        D = 1.0/distance;
        if (distance < radius1 + radius2) {
           center2.x += (center2.x - center1.x) * D * (radius1 + radius2 - distance);
           center2.y += (center2.y - center1.y) * D * (radius1 + radius2 - distance);
           center2.z += (center2.z - center1.z) * D * (radius1 + radius2 - distance);
        }
        return new TVector (center2.x,center2.y,center2.z);
    }
}
